#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <unordered_set>
#include "IniParse.h"

using namespace std;

void test01() {
    map<char, int> _map = {{'a', 1},
                           {'b', '1'},
                           {'b', '2'}};
    _map['a'] = 3;
    for (const auto &pair: _map) {
        cout << pair.first << " " << pair.second << endl;
    }

    cout << "--------------------" << endl;
    multimap<char, int> _mmap = {{'a', 1},
                                 {'b', 1},
                                 {'a', 2}};
    _mmap.insert(make_pair('a', 3));
    for (const auto &_pair: _mmap) {
        cout << _pair.first << " " << _pair.second << endl;
    }

    cout << _map.count('a') << endl;
    cout << _map.count('*') << endl;

    cout << _mmap.count('a') << endl;
    cout << _mmap.count('*') << endl;

    auto it = _map.find('*');
    if (it != _map.end()) {
        cout << it->first << " " << it->second << endl;
    } else {
        cout << "未找到" << endl;
    }

}

// set 集合 去重的 ~~ multi_set 红黑树实现
// unordered_set hash表
void test02() {
    set<int> _set;
    set<int> _set2 = {1, 23, 45, 23, 1};
    set<int> _set3;
    _set3.insert(12);
    _set3.insert(14);
    _set3.insert(13);

    for (auto it = _set2.begin(); it != _set2.end(); ++it) {
        cout << *it << endl;
    }
    cout << "-----------------" << endl;
    unordered_set<int> _set4 = {1, 23, 45, 23, 1};  //去重 但不排序

    for (auto it = _set4.begin(); it != _set4.end(); ++it) {
        cout << *it << endl;
    }
}

void test03() {
    int arr[] = {23, 45, 78, 69, 16};
    set<int> _set;
    for (int i = 0; i < sizeof(arr) / sizeof(int); ++i) {
        _set.insert(arr[i]);
    }
    for (auto it = _set.rbegin(); it != _set.rend(); ++it) {
        cout << *it << endl;
    }
    cout << "---------------------------" << endl;
    set<int> _set2(arr, arr + sizeof(arr) / sizeof(int));
    vector<int> arr2(_set.rbegin(), _set2.rend());
    for (int i = 0; i < arr2.size(); ++i) {
        cout << arr2.at(i) << endl;
    }
}

void test04() {
    IniParse IniParse("D:\\cpp_study\\project\\cpp0616\\iniparse\\dbconfig.ini");
    unordered_map<string, unordered_map<string, string>> ins = IniParse.getData();

    for (auto &elem: ins) {
        cout << elem.first << " " << endl;
        unordered_map<string, string> ins2 = IniParse.getSection(elem.first);
        for (auto &elem1: elem.second) {
            cout << elem1.first << " " << elem1.second << endl;
        }
    }
}

int main() {
    test04();
    // test03();
    // test02();
    // test01();
    return 0;
}